package com.jxd.project.absence.controller;

import com.jxd.project.absence.dto.UpdateAbsenceDto;
import com.jxd.project.absence.model.Absence;
import com.jxd.project.absence.service.IAbsenceService;
import com.jxd.project.absence.service.IUserService;
import com.jxd.project.absence.vo.UserInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName OperationController
 * @Description TODO
 * @Author 李杨
 * @Date 2025/10/8 9:10
 * @Version 1.0
 */
@RestController
public class OperationController {
    @Autowired
    private IUserService userLoginService;
    @Autowired
    private IAbsenceService absenceService;

    @RequestMapping("/login")
    public Map<String,Object> login(@RequestBody Map<String,String> map) {
        return userLoginService.userLogin(map);
    }
    @RequestMapping("/newAbsence")
    public String newAbsence(@RequestBody Absence absence) {
         boolean flag = absenceService.save(absence);
         if (flag) {
             return "success";
         } else {
             return "error";
         }
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(@RequestBody Absence absence) {
        boolean flag = absenceService.saveOrUpdate(absence);
        if (flag) {
            return "success";
        } else {
            return "error";
        }
    }

    @RequestMapping("/delAbsence")
    public String delAbsence(@RequestParam int id){
        return absenceService.removeById(id) ? "success" : "error";
    }

    @RequestMapping("finishAbsence")
    public String finishAbsence(@RequestBody UpdateAbsenceDto updateAbsenceDto){
        return absenceService.updateAbsence(updateAbsenceDto) ? "success" : "error";
    }

    @RequestMapping("/changePassword")
    public String changePassword(@RequestBody Map<String,String> map){
        return userLoginService.changePassword(map) ? "success" : "error";
    }
}
